package Pattern.FacadePattern.Program2;

class FileOperation {
    public String read(String fileName) {  //读取文件代码省略  }
        return "读取文件" + fileName;
    }

    static class XMLDataConvertor {
        public String convert(String fileStr) {  //文件格式转换代码省略  }
            return fileStr + "格式已转换";
        }

        static class DataAnalysis {
            public String handle(String xmlStr) {  //数据分析统计代码省略  }
                return xmlStr + "已分析数据";
            }

            static class ReportDisplay {
                public void display(String xmlStr) {  //报表显示代码省略  }
                    System.out.println(xmlStr+"报表已显示");
                }

                /*(1)*/abstract static class AbstractFacade {
                    public abstract void execute(String fileName);
                }

                static class XMLFacade extends AbstractFacade {
                    private FileOperation fo;
                    private DataAnalysis da;
                    private ReportDisplay rd;

                    public XMLFacade() {
                        fo = new FileOperation();
                        da = new DataAnalysis();
                        rd = new ReportDisplay();
                    }

                    public void execute(String fileName) {
                        String str = fo.read(fileName); /*(2)*/ //读取文件
                        String strResult = da.handle(fileName)/*(3)*/; //分析数据
                        System.out.println(str);
                        System.out.println(strResult);
                        rd.display(fileName);/*(4)*///显示报表
                    }
                }

                class ExtendedFacade extends AbstractFacade {
                    private FileOperation fo;
                    private XMLDataConvertor dc;
                    private DataAnalysis da;
                    private ReportDisplay rd;

                    public ExtendedFacade() {
                        fo = new FileOperation();
                        dc = new XMLDataConvertor();
                        da = new DataAnalysis();
                        rd = new ReportDisplay();
                    }

                    public void execute(String fileName) {
                        String str = fo.read(fileName)/*(5)*/; //读取文件
                        String strXml = dc.convert(fileName)/*(6)*/; //转换文件
                        String strResult = da.handle(fileName)/*(7)*/; //分析数据
                        System.out.println(str);
                        System.out.println(strResult);
                        System.out.println(strXml);
                        rd.display(fileName);/*(8)*///显示报表
                    }
                }

                static class Test {
                    public static void main(String args[]) {
                        AbstractFacade facade;
                        facade = new XMLFacade();/*(9) */
                        facade.execute("file.xml");
                    }
                }
            }
        }
    }
}

